from Inspect import db
from datetime import datetime


# 用户表
class Users(db.Model):
    # id
    # name 用户名称
    # phone 电话
    # password 密码
    # department 部门
    # position 职位
    # jurisdiction 权限
    # portrait 头像
    # code 身份证号
    # updatetime 提交时间
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    phone = db.Column(db.Integer)
    password = db.Column(db.String(200))
    department = db.Column(db.Integer)
    position = db.Column(db.String(200))
    jurisdiction = db.Column(db.Integer)
    portrait = db.Column(db.String(200))
    code = db.Column(db.String(200))
    updatetime = db.Column(db.DateTime, default=datetime.now, index=True)

    def to_json(self):
        dicts = self.__dict__
        if "_sa_instance_state" in dicts:
            del dicts["_sa_instance_state"]
        return dicts


# 部门表
class Departments(db.Model):
    __tablename__ = 'department'
    id = db.Column(db.Integer, primary_key=True)
    departmentName = db.Column(db.String(200))
    updatetime = db.Column(db.DateTime, default=datetime.now, index=True)

    def to_json(self):
        dicts = self.__dict__
        if "_sa_instance_state" in dicts:
            del dicts["_sa_instance_state"]
        return dicts


# 设备表
class Equipments(db.Model):
    __tablename__ = 'equipment'
    id = db.Column(db.Integer, primary_key=True)
    equipmentName = db.Column(db.String)
    position = db.Column(db.String)
    equipmentNumber = db.Column(db.String)
    longitude = db.Column(db.Float)
    latitude = db.Column(db.Float)
    updatetime = db.Column(db.DateTime, default=datetime.now, index=True)

    def to_json(self):
        dicts = self.__dict__
        if "_sa_instance_state" in dicts:
            del dicts["_sa_instance_state"]
        return dicts


# 巡检记录表
class InspectionRecord(db.Model):
    __tablename__ = 'inspectionRecord'
    id = db.Column(db.Integer, primary_key=True)
    equipmentId = db.Column(db.Integer)  # 设备id
    userId = db.Column(db.Integer)  # 用户id
    recordLocation = db.Column(db.String(200))  # 检测时位置
    inspectionTime = db.Column(db.DateTime, default=datetime.now, index=True)  # 检测时间
    updatetime = db.Column(db.DateTime, default=datetime.now, index=True)

    def to_json(self):
        dicts = self.__dict__
        if "_sa_instance_state" in dicts:
            del dicts["_sa_instance_state"]
        return dicts
